package client

import (
	"context"

	"gitee.com/huoyu123hk/cloudAgent/pkg/logx"
)

type AgentConfig struct {
	ServerURL         string `json:"server_url"`
	AuthToken         string `json:"auth_token"`
	AgentID           string `json:"agent_id"`
	KeepAliveInterval int    `json:"keep_alive_interval"`
}

type App struct {
	config AgentConfig
	ctx    context.Context
	agent  *AgentClient
}

func NewApp(c AgentConfig) *App {
	ctx := context.Background()
	return &App{
		config: c,
		ctx:    ctx,
		agent:  NewAgentClient(ctx, c),
	}
}
func (a *App) Run() error {
	err := a.agent.Connect()
	if err != nil {
		logx.Error("Failed to connect to server: %v", err)
		return err
	}

	go a.agent.KeepAlive()
	a.agent.HandleMessages()
	return nil
}

func (a *App) Stop() error {
	// 实现停止应用程序的逻辑
	return nil
}
